// packageA/pages/operate/demonstration/demonstration.js
const App = getApp()

// import moment from '../../../../utils/moment'
import Toast from '../../../../weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: ['申请演示', '开户申请', '申请结佣'],
    follow_form: {
      id:'',
      area:'',
      price:'',
      renew_time:''
    },
    name:'',
    currentIndex: 0,
    show1:false,
    show: false,
    actions:[]
  },

//日历
onDisplay() {
  this.setData({ show: true });
},
onClose() {
  this.setData({ show: false,show1: false });
},
handleSelect(){
  this.setData({ show1: true });
},
onSelect1(event){
  this.setData({
    name:event.detail.name,
    ...this.data.follow_form,
    'follow_form.id':event.detail.id
  })
},
onDayClick(event){
  this.setData({ 
    show: false,
    ...this.data.follow_form,
    'follow_form.renew_time':event.detail.id
   });
  console.log(event.detail)
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList()
  },
  getList(){
    let _this = this
    App._post_form('Business/getBusinessOpen', {
      action:"account_renew_list"
    }, function (result) {
      if (result.code === 0) {
        let arr = result.data.data
        let newArr = []
        for (let index = 0; index < arr.length; index++) {
          let obj = {
            name:arr[index].company_name,
            id:arr[index].id
          }
          newArr.push(obj)
        }
        _this.setData({
          actions:newArr
        })
      }
    });
  },
  inputOnChange(event){
    let {input} = event.currentTarget.dataset
    let value = event.detail
    console.log(event)
    this.setData({
      follow_form:{
        ...this.data.follow_form,
        [input]:value
      }
    })
  },
  handleSaveForm(){
    let _this = this
    let { id,area,price, renew_time} = _this.data.follow_form
    if (!id) {
      Toast.fail('请选择公司名称');
      return false;
    }
    if (!area) {
      Toast.fail('请填写区域');
      return false;
    }
    if (!price) {
      Toast.fail('请填写价格');
      return false;
    }
    if (!renew_time) {
      Toast.fail('请选择续费时间');
      return false;
    }
    console.log(_this.data.follow_form)
    App._post('Business/applyBusinessRenew', _this.data.follow_form, function (result) {
      if (result.code === 0) {
        Toast({
          type: 'success',
          message: '提交成功',
          onClose: () => {
            wx.redirectTo({
              url: '../../operate/index/index',
            })
          },
        });
      }else{
        Toast.fail(result.msg);
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})